﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;
using System.Collections.Generic;
using System.Globalization;
using System.Diagnostics;
using Microsoft.Kinect;
using Coding4Fun.Kinect.Wpf;

namespace TeachNect
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        enum Subjects 
        { Math, Sciencie, English, Geographic, Language, Computation };
        enum Levels
        { first, second, third, fourth, fifth, sixth }

        public static MainWindow Instance { get; set; }

        public KinectSensor sensor { get; private set; }

        #region Data
        int level;
        char Subject;
        char parallel;
        #endregion


        public MainWindow()
        {
            InitializeComponent();
            Instance = this;

            #region AddEventsButtons

            _AppPrincipalControl._AppButton.Click += new RoutedEventHandler(KinectControlVisible);
            _AppPrincipalControl._ExitButton.Click += new RoutedEventHandler(AppPrincipalClose);
            _AppKinectControl.BackButton.Click += new RoutedEventHandler(KinectControlCollapse);
            #endregion
        }


        #region Button Events

            private void KinectControlVisible(object sender, RoutedEventArgs e)
            {
                _AppKinectControl.Visibility = Visibility.Visible;
                _AppPrincipalControl.Visibility = Visibility.Collapsed;
            }


            private void KinectControlCollapse(object sender, RoutedEventArgs e)
            {
                _AppKinectControl.Visibility = Visibility.Collapsed;
                _AppPrincipalControl.Visibility = Visibility.Visible;
            }


            

            private void ChooseLevel(object sender, RoutedEventArgs e)
            {
                _AppKinectControl.Visibility = Visibility.Collapsed;
                _AppPrincipalControl.Visibility = Visibility.Visible;
            }


            
            private void _fillPupilChoose(int Level, char Subject, char Parallel)
            { 
            }
            private void _fillApplications(int Level, char Subject, char Parallel)
            {
            }
            private void _fillStatics(int Level, char Subject, char Parallel)
            {
            }


            private void AppPrincipalClose(object sender, RoutedEventArgs e)
            {
                this.Close();
            }



        #endregion
        
        #region KinectCode
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (KinectSensor.KinectSensors.Count > 0)
                {
                    //grab first
                    sensor = KinectSensor.KinectSensors[0];
                }

                if (sensor.Status != KinectStatus.Connected || KinectSensor.KinectSensors.Count == 0)
                {
                    MessageBox.Show("No Kinect connected!");
                }

                // Set up the Kinect

                var parameters = new TransformSmoothParameters
                {
                    Smoothing = 0.3f,
                    Correction = 0.0f,
                    Prediction = 0.0f,
                    JitterRadius = 1.0f,
                    MaxDeviationRadius = 0.5f
                };

                sensor.SkeletonStream.Enable(parameters);
                sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                sensor.Start();
            }
            catch (Exception)
            {
                _AppPrincipalControl.PART_ErrorText.Visibility = Visibility.Visible;
                sensor = null;
            }
        }
        private void Window_Closed(object sender, EventArgs e)
        {
            if (sensor != null)
                if (sensor.IsRunning)
                {
                    sensor.Stop();
                }
            Environment.Exit(0);
        }
        #endregion
    }
}
